package com.xyc.servlet.user;

import com.xyc.mapper.UserMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/deleteUser")
public class DeleteUserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //  接收uuid 值    并在数据库中查询并删除
        req.setCharacterEncoding("utf-8");
        String user_id = req.getParameter("id_delete");
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        UserMapper userMapper = ctx.getBean("userMapper", UserMapper.class);
        userMapper.deleteUserById(user_id);
        req.getRequestDispatcher("myUser").forward(req, resp);
    }
}
